package com.crawler.parser;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.crawler.pojo.Constant;

public class OrderDetialPageParser extends ParserAdapter {

	/**
	 * 解析订单收货地址
	 */
	@Override
	public String parseText(String type, String html) {
		String address = "";
		if(type.equals(Constant.orderState_已完成)){
			address = parse1024(html);
		}
		if(type.equals(Constant.orderState_等待付款)){
			address = parse1(html);
		}
		if(type.equals(Constant.orderState_等待自提)){
			address = parse32(html);
		}
		if(type.equals(Constant.orderState_已取消)){
			address = parse_1(html);
		}
		if(type.equals(Constant.orderState_等待收货) || type.contains(Constant.orderState_等待收货)){
			address = parse128(html);
		}
		return address;
	}

	private String parse128(String html) {
		return parse1024(html);
	}

	private String parse_1(String html) {
		Document doc = Jsoup.parse(html);
		Elements tds = doc.select("tbody").get(2).select("td");
		return tds.get(1).text()+" "+tds.get(3).text()+" "+tds.get(5).text();
	}

	private String parse32(String html) {
		return "";
	}

	private String parse1(String html) {
		return "";
	}

	private String parse1024(String html) {
		Document doc = Jsoup.parse(html);
		Element orderinfo = doc.getElementById("orderinfo");
		String yoyo = orderinfo.select("dl").first().select("li").first().text();
		String you = yoyo.substring(yoyo.indexOf("：")+1, yoyo.length());
		
		yoyo = orderinfo.select("dl").first().select("li").get(1).text();
		String address = yoyo.substring(yoyo.indexOf("：")+1, yoyo.length());
		
		yoyo = orderinfo.select("dl").first().select("li").get(2).text();
		String phone = yoyo.substring(yoyo.indexOf("：")+1, yoyo.length());
		
		return  you+" "+phone +" "+address;
	}
	
}
